package com.gancai.admin.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gancai.admin.entity.po.AdminUserPo;
import com.gancai.admin.service.AdminUserService;
import com.gancai.model.entity.TestEntity;
import com.gancai.model.utill.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author GanGan
 */
@RefreshScope //开启配置文件刷新
@RestController
public class TestController {

    @Value("${admin.test}")
    String test;

    @Autowired
    private AdminUserService adminUserService;


    @GetMapping("/test")
    @SentinelResource(value = "test")
    public Result test(@RequestBody String userName, String password){
        Result result = new Result();
        QueryWrapper<AdminUserPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",userName);
        queryWrapper.eq("password",password);


        List<AdminUserPo> adminUserServicesList= adminUserService.list(queryWrapper);
        boolean empty = adminUserServicesList.isEmpty();
        if(empty){
            return result.error("用户名或密码错误");
        }

        result.ok(adminUserServicesList);

        return result;
    }




}
